// 原生JavaScript处理
// 中间部分的高度设置
// let nav_height = document.getElementById("nav").offsetHeight;
// let content_height = document.getElementById("content").offsetHeight;
// let basicBox_height = (nav_height > content_height) ? nav_height : content_height;
// document.getElementById("basicBox").style.height = basicBox_height + 40 + "px";

// 获取用户参数
var userParameter = location.href;
var n1 = userParameter.length;
var n2 = userParameter.indexOf('=');
var userName = decodeURI(userParameter.substr(n2 + 1, n1 - n2)); // userName就是用户参数

// Vue代码
const vm = new Vue({
    el: '#app',
    data() {
        return {
            userName: userName,
            isShowUserInfor: false,
            isShowToTop: false,
            loggerData: [],
            dataBegin: 0,
            dataEnd: 30
        }
    },
    methods: {
        getManage: function () {
            location.href = 'lockmanage.html?' + 'user=' + encodeURI(userName);
        },
        getLogger: function () {
            var that = this;
            axios.get("//81.69.27.130/product/LoggerByuser/" + userName)
                .then(function (response) {
                    that.loggerData = response.data;
                    for (var i = 0, j = that.loggerData.length - 1; i < j; ++i, --j) {
                        var t = that.loggerData[i];
                        that.loggerData[i] = that.loggerData[j];
                        that.loggerData[j] = t;
                    }
                    for (var i = 0 in that.loggerData) {
                        // 修改时间样式
                        let timeInfor = new Date(that.loggerData[i].time);
                        that.loggerData[i].time = timeInfor.toLocaleString();
                        // 转换状态
                        if (that.loggerData[i].openState == 0) {
                            that.loggerData[i].openState = '关锁';
                        } else {
                            that.loggerData[i].openState = '开锁';
                        }
                        if (that.loggerData[i].success == 0) {
                            that.loggerData[i].success = '失败';
                        } else {
                            that.loggerData[i].success = '成功';
                        }
                        // 新增序号
                        that.loggerData[i].index = Number(i) + 1;
                    }
                }, function (err) {
                    console.log(err);
                })
        },
        getIdLogger: function () {
            let that = this;
            let lockId = document.getElementById("lockId").value;
            this.dataBegin = 0;
            this.dataEnd = 30;
            axios.get("//81.69.27.130/product/LoggerByLockId/" + lockId)
                .then(function (response) {
                    // console.log(response)
                    that.loggerData = response.data;
                    for (var i in that.loggerData) {
                        // 修改时间样式
                        let timeInfor = new Date(that.loggerData[i].time);
                        that.loggerData[i].time = timeInfor.toLocaleString();
                        // 转换状态
                        if (that.loggerData[i].openState == 0) {
                            that.loggerData[i].openState = '关锁';
                        } else {
                            that.loggerData[i].openState = '开锁';
                        }
                        if (that.loggerData[i].success == 0) {
                            that.loggerData[i].success = '失败';
                        } else {
                            that.loggerData[i].success = '成功';
                        }
                        // 新增序号
                        that.loggerData[i].index = Number(i) + 1;
                    }
                }, function (err) {
                    console.log(err);
                })
        },
        getState: function () {
            location.href = 'index.html?' + 'user=' + encodeURI(userName);
        },
        deleteLogger(id) {
            axios.get("//81.69.27.130/product/deleteLoggerById/" + id)
                .then(function (response) {
                    // console.log(response.data.message);
                    alert("删除成功！");
                    location.reload();
                }, function (err) {
                    console.log(err)
                })
        },
        lastPage: function () {
            this.dataBegin -= 30;
            this.dataEnd -= 30;
        },
        nextPage: function () {
            this.dataBegin += 30;
            this.dataEnd += 30;
        },
    },
    mounted() {
        this.getLogger();
        $("#lastPage").hide();
    },
    created() {
        var _this = this;
        window.onscroll = function () {
            // 滚动条滚动的距离
            var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
            if (scrollTop >= 500) {
                _this.isShowToTop = true;
            } else {
                _this.isShowToTop = false;
            }
        }
    }
})
// jQuery代码
$(document).ready(function () {
    $('#nav').on('click', '.navItermA', function () {
        $(this).removeClass("navItermA").siblings().addClass("navItermA");
        $(this).addClass("navItermB").siblings().removeClass("navItermB");
    });
})